
from django.contrib.auth.models import AbstractUser
from django.db import models


class BaseModel(models.Model):
    # create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='更新时间')

    class Meta:
        abstract = True  # 可以被子类继承，在migrate时不会产生这个模型


class User(BaseModel, AbstractUser):
    # username = models.CharField(max_length=20, verbose_name='用户名')
    # password = models.CharField(max_length=128, verbose_name='密码')
    phone = models.CharField(max_length=11, verbose_name='手机号码')
    usertype = models.SmallIntegerField(choices=((1, '普通用户'),(2, '管理员')), default=2, verbose_name='用户类型')

    class Meta:
        db_table = 'user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name


class VerifyCode(BaseModel):
    code = models.CharField(max_length=4)
    phone = models.CharField(max_length=11)

    class Meta:
        db_table = 'verify_code'
        verbose_name = '验证码'
        verbose_name_plural = verbose_name


